const {SyncHook} = require('tapable');
const Hook = new SyncHook(['name','age']);
let interceptor1 = {
    //当你注册一个新的事件函数时触发
    register(tapInfo) {
        console.log('拦截器1 register', tapInfo.name);
        tapInfo.age = 12;
        return tapInfo
    },
    tap(tapInfo) {//tap拦截是在每个事件触发的时候执行
        console.log('拦截器1 tap',tapInfo.name);
    },
    call: (name,age) => {//每个call会触发一次call拦截器,事件处理之前
        console.log('拦截器1 call', name,age);
    }
}

let interceptor2 = {
    //当你注册一个新的事件函数时触发
    register(tapInfo) {
        console.log('拦截器2 register',tapInfo.name);
        return tapInfo
    },
    tap(tapInfo) {
        console.log('拦截器1 tap',tapInfo.name);
    },
    call: (name,age) => {
        console.log(`拦截器2 call`,name,age);
    }
}

Hook.intercept(interceptor1)
Hook.intercept(interceptor2)

Hook.tap({name:"事件函数A"},(name,age)=>{
    console.log("事件函数A",name,age);
})

Hook.tap({ name: "事件函数B" }, (name, age) => {
    console.log("事件函数B", name, age);
})

debugger
Hook.call("zhufeng",'age')